package com.eqdd.yiqidian.ui.select;

import android.databinding.DataBindingUtil;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;

import com.eqdd.yiqidian.R;
import com.eqdd.yiqidian.ShowRichTextActivityCustom;
import com.eqdd.yiqidian.adapter.recycleadapter.ItemClickSupport;
import com.eqdd.yiqidian.adapter.slimadapter.SlimAdapterEx;
import com.eqdd.yiqidian.adapter.slimadapter.SlimInjector;
import com.eqdd.yiqidian.adapter.slimadapter.viewinjector.IViewInjector;
import com.eqdd.yiqidian.base.BaseActivity;
import com.eqdd.yiqidian.base.Config;
import com.eqdd.yiqidian.utils.ImageUtil;
import com.luck.picture.lib.PictureSelector;
import com.luck.picture.lib.config.PictureConfig;
import com.luck.picture.lib.entity.LocalMedia;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ShowRichTextActivity extends BaseActivity {
    private ShowRichTextActivityCustom dataBinding;
    private List<LocalMedia> imagePath = new ArrayList<>();
    private Map<Integer, Integer> map = new HashMap<>();
    private boolean isShow = false;
    private List<LocalMedia> localList = new ArrayList<>();

    @Override
    public void initBinding() {
        dataBinding = DataBindingUtil.setContentView(this, R.layout.activity_show_rich_text);
        initTopTitleBar(View.VISIBLE, "详情");
    }

    @Override
    public void initData() {
        String title = getIntent().getStringExtra(Config.TITLE);
        initTopTitleBar(View.VISIBLE, TextUtils.isEmpty(title) ? "请填写" : title);
        RichTextResult richTextResult = (RichTextResult) getIntent().getSerializableExtra(Config.RICH_TEXT_RESULT);
        if (richTextResult != null) {
            localList = richTextResult.getSelectMedia();
            imagePath.addAll(localList);
            dataBinding.etContent.setText(TextUtils.isEmpty(richTextResult.getContent()) ? "" : richTextResult.getContent());
        }
    }

    @Override
    public void setView() {

        dataBinding.recyclerView.setLayoutManager(new GridLayoutManager(this, 3));
        SlimAdapterEx slimAdapterEx = SlimAdapterEx.create().register(R.layout.list_item_image_1, new SlimInjector<LocalMedia>() {
            @Override
            public void onInject(LocalMedia data, IViewInjector injector) {
                injector.image(R.id.image,data.getPath());
            }
        }).attachTo(dataBinding.recyclerView);
        ItemClickSupport.addTo(dataBinding.recyclerView).setOnItemClickListener((recyclerView, position, v) -> {
            PictureSelector.create(ShowRichTextActivity.this).externalPicturePreview(position, localList);
        });
        slimAdapterEx.updateData(imagePath);
    }


    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {

        }
    }
}
